/*
 ------------------------------------------------------------------------------
	sdlmad - a test program for using mad library with SDL on Win32
	and Linux.

	Copyright (C) 2011 Pierre Veber
	
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 3 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software Foundation,
	Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
------------------------------------------------------------------------------
*/

#pragma once

/* audio engine data and functions */
#ifdef WIN32
typedef struct {
	HWAVEOUT	hWaveOut;
	HANDLE		hFreeBlock;
	WAVEHDR*	pHdr;
	LPSTR		pWaveData;
} audio_data_t;
#else
typedef struct {
	snd_pcm_t*	pHandle;
} audio_data_t;
#endif

int waveInit(
			audio_data_t* pAudio
			);

int waveWriteIn(
			audio_data_t* pAudio,
			const void* pBuffer,
			unsigned int frames
			);

void waveReset(
			audio_data_t* pAudio
			   );

void waveClose(
			audio_data_t* pAudio
			);

/* decoding data and functions */
typedef struct {
	FILE*				fp;
	char*				szFilePath;
	struct mad_decoder	decoder;
	audio_data_t		audio;
	pthread_t			tDecodeThread;
	int					status;
	int					msg;
} decode_thread_data_t;

#define DECODE_STATUS_NONE			0
#define DECODE_STATUS_DECODING	1
#define DECODE_STATUS_FINISHED	2

#define DECODE_MSG_NONE		0
#define DECODE_MSG_STOP		1

void send_message(decode_thread_data_t* pData, int msg);
int get_message(decode_thread_data_t* pData);
decode_thread_data_t* madDecode(audio_data_t* pAudio, const char* pszFile);
int madStop(decode_thread_data_t* pDecodeThreadData);

/* id3 */

